<% layout('/layouts/default.html', {title: '检修车回送单管理', libs: ['validate']}){ %>

<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(tblXdJxchsd.isNewRecord ? '新增检修车回送单' : '编辑检修车回送单')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${tblXdJxchsd}" action="${ctx}/tbl/replyform/tblXdJxchsd/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="recId"/>
				<div class="row">
<!--					<div class="col-xs-4">-->
<!--						<div class="form-group">-->
<!--							<label class="control-label col-sm-4" title="">-->
<!--								<span class="required">*</span> ${text('发站')}：<i class="fa icon-question hide"></i></label>-->
<!--							<div class="col-sm-8">-->
<!--								<#form:input path="sendStationCode" maxlength="2" class="form-control required"/>-->
<!--								<#form:hidden path="sendStation"/>-->
<!--							</div>-->
<!--						</div>-->
<!--					</div>-->
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('检车人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="jcrCode" items="${jcrList}" itemLabel="jcrName" itemValue="jcrCode" blankOption="true" class="form-control required" onchange="selChange()"/>
								<#form:hidden path="jcrName"/>
							</div>
						</div>
					</div>

<!--					<div class="col-xs-4">-->
<!--						<div class="form-group">-->
<!--							<label class="control-label col-sm-4" title="">-->
<!--								<span class="required">*</span> ${text('到站')}：<i class="fa icon-question hide"></i></label>-->
<!--							<div class="col-sm-8">-->
<!--								<#form:input path="arriveStationCode" maxlength="2" class="form-control required"/>-->
<!--								<#form:hidden path="arriveStation"/>-->
<!--							</div>-->
<!--						</div>-->
<!--					</div>-->
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('入修地点')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								 <#form:select path="repairLineCode" items="${rlcList}" itemLabel="XLMC" blankOption="true" itemValue="XLBH" class="form-control required" onchange="rlcChange()"/>
<!--								<#form:input path="repairLineCode" maxlength="10" class="form-control required"/>-->
								<#form:hidden path="repairLineName"/>
							</div>
						</div>
					</div>

					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('是否禁峰')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="isNopeak" dictType="sys_yes_no" blankOption="true" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('扣车类别')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="faultItemCode" items="${kclbList}" blankOption="true" itemLabel="kclbName" itemValue="kclbCode" class="form-control required" onchange="kclbChange()"/>
								<#form:hidden path="faultItemName"/>
							</div>
						</div>
					</div>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('扣车原因')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="faultCode" items="${kcyyList}" blankOption="true" itemLabel="faultName" itemValue="faultCode" class="form-control required" onchange="kcyyChange()"/>
								<#form:hidden path="faultName"/>
							</div>
						</div>
					</div>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('限速')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="speedLimit" maxlength="50" class="form-control" list="limitlist"/>
								<datalist id="limitlist"></datalist>
							</div>
						</div>
					</div>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('入修类别')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="repairMethodCode" dictType="rxlb" blankOption="true" class="form-control required" onchange="rxlbChange()"/>
								<#form:hidden path="repairMethod"/>
							</div>
						</div>
					</div>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('入修方式')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="repairMethodDetailCode" dictType="rxfs" blankOption="true" class="form-control required" onchange="rxfsChange()" />
								<#form:hidden path="repairMethodDetail"/>
							</div>
						</div>
					</div>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
							<div class="col-sm-8">
								<#form:hidden path="ids"/>
							</div>
						</div>
					</div>

					<div class="col-xs-8">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:input path="remark" maxlength="100" class="form-control"  />
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<div class="row text-right">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$(function(){
	var speedlimit= ${@DictUtils.getDictListJson('speedlimit')};
	var speedHtml = "";
	$.each(speedlimit,function(i,item){
		speedHtml += "<option value='"+item.dictLabel+"'>"+item.dictLabel+"</option>"
	});
	$("#limitlist").append(speedHtml);
	
	var repairMethodDetailCode = $("#repairMethodDetailCode").val();

	$.ajax({
		type:"POST",
		url:"${ctx}/sys/dictData/treeData?dictType=rxfs",
		dataType:"json",
		success: function(json){
			var typeSelect = $("#repairMethodDetailCode")[0];
			typeSelect.options.length=0;
			//往父级下拉框中追加父级字典
			for (var i of json) {
				if (i.value == repairMethodDetailCode) {
					typeSelect.options.add(new Option(i.name, i.value, false, i.value == repairMethodDetailCode));
				}
			}
		}
	});
	
	var params={"kclb":$("#faultItemCode").val()};
	var kcyy = $("#faultCode").val();

	$.post("${ctx}/tbl/kclb/tblZdKcyy/listData2",params,function(data){

		var faultCode = $("#faultCode")[0];  //清空原来下拉框的值
		faultCode.options.length = 0;

		//进行循环判断并追加数据到二级下拉框中
		for (var i of data) {
			if (i.faultCode == kcyy) {
				faultCode.options.add(new Option(i.faultName, i.faultCode));  //往下拉框中追加值
			}
		}
		
	},"json");
})
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});

function selChange(){
	var jcrName = $("#jcrCode").find("option:selected").text();
	$("#jcrName").val(jcrName);
}


function rlcChange(){
	var XLMC = $("#repairLineCode").find("option:selected").text();

	$("#repairLineName").val(XLMC);

}

function kclbChange(){
	var params={"kclb":$("#faultItemCode").val()};
	$.post("${ctx}/tbl/kclb/tblZdKcyy/listData2",params,function(data){

		var faultCode = $("#faultCode")[0];  //清空原来下拉框的值
		faultCode.options.length = 0;//加空白选项

		//进行循环判断并追加数据到二级下拉框中
		for (var i of data) {
			faultCode.options.add(new Option(i.faultName, i.faultCode));  //往下拉框中追加值
		}
		
	},"json");
	
	var kclbName = $("#faultItemCode").find("option:selected").text();
	$("#faultItemName").val(kclbName);
	
	$("#faultCode").attr("selected",false);
}

function kcyyChange(){
	var kcyyName = $("#faultCode").find("option:selected").text();
	$("#faultName").val(kcyyName);
}

function rxlbChange(){
	var repairMethod = $("#repairMethodCode").find("option:selected").text();
	$("#repairMethod").val(repairMethod);
	
	$.ajax({
		type:"POST",
		url:"${ctx}/sys/dictData/treeData?dictType=rxfs",
		dataType:"json",
		success: function(json){
			var type = $('#repairMethodDetailCode option:selected').val();
			var typeSelect = $("#repairMethodDetailCode")[0];
			typeSelect.options.length=0;
			var repairMethodCode = $('#repairMethodCode option:selected').val();
			//往父级下拉框中追加父级字典
			for (var i of json) {
				if (i.value.substr(0, 1) == repairMethodCode) {
					typeSelect.options.add(new Option(i.name, i.value, false, i.value == repairMethodCode));
				}
			}
		}
	});
}

function rxfsChange(){
	var repairMethodDetail = $("#repairMethodDetailCode").find("option:selected").text();
	$("#repairMethodDetail").val(repairMethodDetail);
}

</script>
<style>
	body{
		height: 100%;
	}
	.main-content{
		height: 100%;
	}
	.box{
		height: 100%;
	}
</style>